package com.dada.repository.dada;

import com.dada.dada.domain.tables.pojos.User;
import com.dada.dada.domain.tables.records.UserRecord;
import com.dada.domain.qos.UserQO;
import com.dada.repository.AbstractDadaRepository;
import org.apache.commons.lang3.tuple.Pair;
import org.jooq.Table;
import org.jooq.UpdatableRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by jianweilin on 16/9/5.
 */
@Repository
public class UserRepository extends AbstractDadaRepository<UserRecord> {

    @Override
    protected Pair<Class<UserRecord>, Table<? extends UpdatableRecord>> mapping() {
        return Pair.of(UserRecord.class,USER);
    }

    /**
     *  根据id查询用户
     */
    public List<User> findById(Integer id){
        UserQO query = UserQO.builder().id(id).build();
        return dsl.select().from(USER).where(query.conditions()).fetchInto(User.class);
    }
}
